package org.agony2d.view 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import org.agony2d.notify.AEvent;
	import org.agony2d.view.puppet.DisplayObjectContainerPuppet;
	import org.agony2d.view.supportClasses.AbstractRange;
	import org.agony2d.utils.getInstance;
	
	import org.agony2d.core.agony_internal;
	use namespace agony_internal;
	
public class ProgressBar extends AbstractRange 
{
	
	public function ProgressBar( movieClipData:*, v:Number = 0, min:Number = 0, max:Number = 100, snapInterval:Number = 0 ) 
	{
		super(v, min, max, snapInterval)
		
		m_container = new DisplayObjectContainerPuppet()
		this.addElement(m_container)
		m_movieClip = getInstance(movieClipData) as MovieClip
		m_container.addChild(m_movieClip)
		m_range.addEventListener(AEvent.CHANGE, ____onRangeChange, true)
	}
	
	
	/** 容器 **/
	final public function get container() : DisplayObjectContainerPuppet
	{
		return m_container
	}
	
	
	agony_internal function ____onRangeChange(e:AEvent) : void
	{
		this.updateValue()
	}
	
	final agony_internal function updateValue() : void
	{
		var r:Number, n:Number
		
		r  =  m_movieClip.totalFrames * m_range.ratio
		n  =  int(r)
		
		m_movieClip.gotoAndStop((r != 0) ? (r != n ? n + 1 : n) : 1)
	}
	
	
	override agony_internal function dispose() : void
	{
		super.dispose()
		m_container = null
		m_movieClip = null
	}
	
	
	agony_internal var m_movieClip:MovieClip
	
	agony_internal var m_container:DisplayObjectContainerPuppet
}
}